﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using SnakeGame.ViewModels;

namespace SnakeGame.Views
{
    /// <summary>
    /// Interaction logic for CharacterPage.xaml
    /// </summary>
    public partial class CharacterPage : Page
    {
        private CharacterPageViewModel _characterPageViewModel;

        public CharacterPage()
        {
            InitializeComponent();

            _characterPageViewModel = (CharacterPageViewModel)DataContext;
        }

        internal void Initilize(MainFrame mainframe)
        {
            _characterPageViewModel.Initialize(mainframe);
        }

        private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listbox = sender as ListBox;
            if (listbox != null)
            {
                _characterPageViewModel.SelectPlayerCommand.Execute(listbox.SelectedItem);
            }
        }

        private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            var control = e.OriginalSource as FrameworkElement;
            if (control == null)
            {
                return;
            }

            var item = control.DataContext as CharacterPageViewModel.CharacterModel;
            if (item != null)
            {
                _characterPageViewModel.SelectCharacterCommand.Execute(item);
            }
        }
        private void Charater_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listview = sender as ListView;
            if (listview != null)
            {
                _characterPageViewModel.SelectCharacterCommand.Execute(listview.SelectedItem);
            }
        }

    }
}
